﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zgq.CommonTools
{
    public class C5Exception : Exception
    {
        private C5Exception() { }

        public C5Exception(string message) : base(message) { }

        public C5Exception(string message, Exception innerException) : base(message, innerException) { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_exceptionGrade">异常等级</param>
        /// <param name="message">消息</param>
        /// <param name="innerException">内部异常</param>
        public C5Exception(ExceptionGrade _exceptionGrade, string message, Exception innerException)
            : this(message, innerException)
        {
            switch (_exceptionGrade)
            {
                case ExceptionGrade.Info:
                    _ExceptionCode = 1;
                    break;
                case ExceptionGrade.Warn:
                    _ExceptionCode = 2;
                    break;
                case ExceptionGrade.Error:
                    _ExceptionCode = 3;
                    break;
            }
            this._C5ExceptionGrade = _exceptionGrade;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_exceptionGrade">异常等级</param>
        /// <param name="message">消息</param>
        public C5Exception(ExceptionGrade _exceptionGrade, string message)
            : this(_exceptionGrade, message, null)
        {
            this._C5ExceptionGrade = _exceptionGrade;
        }

        private ExceptionGrade _C5ExceptionGrade = ExceptionGrade.Info;
        /// <summary>
        /// 异常等级
        /// </summary>
        public ExceptionGrade C5ExceptionGrade
        {
            get { return _C5ExceptionGrade; }
        }

        private int _ExceptionCode = 1000;
        /// <summary>
        /// 异常编码
        /// </summary>
        public int ExceptionCode
        {
            get { return _ExceptionCode; }
            set
            {
                if (_C5ExceptionGrade == ExceptionGrade.Custom && _ExceptionCode < 1000)
                {
                    throw new C5Exception(ExceptionGrade.Error, "自定义的异常编码，不能小于1000");
                }
            }
        }
    }

    public enum ExceptionGrade
    {
        Error,
        Warn,
        Info,
        Custom
    }
}
